package cumt.kydd.authoringplatform.service;


import cumt.kydd.authoringplatform.mapper.HistoryMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static cumt.kydd.authoringplatform.service.UserService.LoginInUser;


@Service
public class ResumeHistoryService {

    @Resource
    private HistoryMapper historyMapper;

    public List<Integer> getUsersHistoryTrashID()
    {
        List<Integer> result = new LinkedList<>();
        result = historyMapper.selectHistoryIDByNameAndIsDeleteYet(LoginInUser.getName());

        return result;
    }


    public Map<String,Object> resumeHistory(int is_delete,int flag_now_his){

        List<Integer> IDList = getUsersHistoryTrashID();
        int flag_now_id = IDList.get(flag_now_his);
//        System.out.println("要恢复的id "+flag_now_id);
        int result = historyMapper.updateIsDelete(is_delete,flag_now_id);
        Map<String,Object> resultMap=new HashMap<>();
        if(result>0)
        {
            resultMap.put("code",200);
            resultMap.put("message","恢复成功！");
        }
        else
        {
            resultMap.put("code",400);
            resultMap.put("message","未知错误，恢复失败!");
        }
        return resultMap;
    }
}
